package com.github.yoojia.mqtt.boot;

import com.github.yoojia.mqtt.boot.utils.Classes;
import com.parkingwang.lang.data.Config;

/**
 * @author Yoojia Chen (yoojiachen@gmail.com)
 * @since 1.0.0
 */
final class ActuatorConf {

    public final String className;
    public final PatternType patternType;
    public final String tagFilter;
    public final boolean disabled;
    public final Config arguments;

    private ActuatorConf(String className, String patternType, String tagFilter, boolean disabled, Config arguments) {
        if (className.contains(".")) {
            this.className = className;
        } else {
            this.className = "com.github.yoojia.mqtt.boot.actuators." + className;
        }
        this.patternType = PatternType.of(patternType);
        this.tagFilter = tagFilter;
        this.disabled = disabled;
        this.arguments = arguments;
    }

    public ReqRepActuator newReqRepActuator() {
        return Classes.newInstance(className);
    }

    public PubSubActuator newEventActuator() {
        return Classes.newInstance(className);
    }

    static ActuatorConf of(Config config) {
        return new ActuatorConf(
                config.getString("class"),
                config.getString("pattern-type"),
                config.getString("tag-filter"),
                config.getBoolean("disabled"),
                config.getConfig("arguments")
        );
    }
}
